'use strict';

const Service = require('../core/common');

class UserGoodsService extends Service {
  findAll(params = {}) {
    const { ctx } = this;

    const { userId } = ctx.params;
    const { attributes, goodsPrizesAttributes, throughWhere } = params;

    return ctx.model.Goods.findAndCountAll({
      attributes,
      include: [{
        attributes: [],
        model: ctx.model.Users,
        through: {
          where: { userId, ...throughWhere },
        },
        where: { id: userId },
      }, {
        attributes: goodsPrizesAttributes,
        model: ctx.model.GoodsPrizes,
      }],
    });

    //   return ctx.model.Users.findAndCountAll({
    //     attributes,
    //     include: [{
    //       attributes: goodsAttributes,
    //       model: ctx.model.Goods,
    //       include: {
    //         attributes: goodsPrizesAttributes,
    //         model: ctx.model.GoodsPrizes,
    //       },
    //       through: {
    //         attributes: [],
    //         where: { userId, ...throughWhere },
    //       },
    //       // required: true,
    //     }],
    //     // required: true,
    //     // distinct: true,
    //     where: { id: userId },
    //   });
  }


  create(params = {}) {
    const { ctx } = this;

    return ctx.model.UsersGoods.create(params);
  }
}

module.exports = UserGoodsService;